package com.k8.rpc.invoke.invocation;

import com.k8.rpc.expoter.Exporter;
import com.k8.rpc.invoke.InvokeMode;
import com.k8.rpc.invoke.Invoker;
import com.k8.rpc.util.RpcUtils;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.Map;
import java.util.concurrent.Future;

/**
 * 提前准备好静态参数，每次调用只用新建{@link RpcInvocation}，不用对静态参数进行传递
 * 作用于提供者端
 */
public class RpcInvocationTemplate implements Invocation {
    private final Method method;
    private final String invocationKey;
    private final Exporter<?> exporter;
    private final InvokeMode invokeMode;

    public RpcInvocationTemplate(Method method,
                                 InvokeMode invokeMode,
                                 String invocationKey
            , Exporter<?> exporter) {
        assert invokeMode != null;
        assert method != null;
        assert invocationKey != null;
        assert exporter != null;
        this.invokeMode = invokeMode;
        this.method = method;
        this.invocationKey = invocationKey;
        this.exporter = exporter;
    }


    @Override
    public InvokeMode getInvokeMode() {
        return this.invokeMode;
    }

    @Override
    public String getMethodName() {
        return this.method.getName();
    }

    @Override
    public Class<?>[] getParameterTypes() {
        return this.method.getParameterTypes();
    }


    public Invoker<?> getInvoker() {
        return this.exporter.getInvoker();
    }


    public String getInvocationKey() {
        return invocationKey;
    }

    @Override
    public Type getReturnType() {
        return method.getGenericReturnType();
    }

    @Override
    public void setTemplate(Invocation invocation) {
        throw new IllegalStateException("Template not need template");
    }

    @Override
    public Invocation getTemplate() {
        return null;
    }

    @Override
    public final Map<String, String> getAttachments() {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }


    @Override
    public final Map<String, Object> getObjectAttachments() {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final Map<String, Object> copyObjectAttachments() {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final void setAttachment(String key, Object value) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final Object[] getArguments() {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final void setObjectAttachmentIfAbsent(String key, Object value) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final String getAttachment(String key) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final Object getObjectAttachment(String key) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final String getAttachment(String key, String defaultValue) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

    @Override
    public final Object getObjectAttachment(String key, Object defaultValue) {
        throw new IllegalStateException("RpcInvocationTemplate just a template");
    }

}
